﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Properties="clr-namespace:Trader.Runner.Properties"
    xmlns:Yahoo="clr-namespace:Trader.DataServices.Yahoo;assembly=Trader.DataServices.Yahoo"
    xmlns:Charts="clr-namespace:Swordfish.WPF.Charts;assembly=Swordfish.WPF.Charts"
    xmlns:TechnicalAnalysis="clr-namespace:Trader.Indicators.TechnicalAnalysis;assembly=Trader.Indicators.TechnicalAnalysis"
    x:Class="Trader.Runner.Window1"
    Title="Trader" WindowState="Maximized" Height="768" Width="1024" >
    <Window.Resources>
        <Yahoo:DataProvider x:Key="dataProvider" x:Name="dataProvider"/>
        <TechnicalAnalysis:SignalsFactory x:Key="signalsFactory"/>
        <Properties:Settings x:Key="settings" />
        <SolidColorBrush x:Key="ButtonsBrush" Color="#FF7C7C7C"/>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>


        <Grid.Background>
            <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                <GradientStop Color="#FFF7F3F3" Offset="0"/>
                <GradientStop Color="BurlyWood" Offset="1"/>
                <GradientStop Color="#FFDEFFE4" Offset="0.536"/>
            </LinearGradientBrush>
        </Grid.Background>


        <TabControl IsSynchronizedWithCurrentItem="True" Grid.Column="0" x:Name="tabControl" Background="{x:Null}" BorderThickness="5,5,5,5">
            <TabItem Header="Configurations" Background="{x:Null}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="Auto" MinHeight="20" />
                        </Grid.RowDefinitions>
                        <ListView IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=Stocks, Source={StaticResource dataProvider}, Mode=OneTime}" x:Name="stocksListView" SelectionMode="Multiple" Grid.ColumnSpan="2" Margin="1,0,-1,0">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid >
                                        <TextBlock Text="{Binding Path=.}" />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                        <Button   Content="All" Click="selectAllButton_Click"  Grid.Row="1"  Background="{DynamicResource ButtonsBrush}"  />
                        <Button   Content="Clear" Click="clearButton_Click"  Grid.Row="1" Grid.Column="1" Background="{DynamicResource ButtonsBrush}"/>

                    </Grid>
                    <Grid Grid.Column="1" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="126" />
                            <ColumnDefinition Width="Auto" MinWidth="66" />
                            <ColumnDefinition Width="Auto" MinWidth="26" />
                            
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" MinHeight="22.864" />
                            <RowDefinition Height="Auto" MinHeight="23" />
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" MinHeight="23" />
                            <RowDefinition Height="Auto" MinHeight="23" />
                            <RowDefinition Height="Auto" MinHeight="23" />
                            <RowDefinition Height="Auto" MinHeight="23" />
                            <RowDefinition Height="Auto" MinHeight="287" />
                            <RowDefinition Height="Auto" MinHeight="20" />
                            <RowDefinition Height="Auto" MinHeight="20" />
                            <RowDefinition Height="Auto" MinHeight="15" />
                            <RowDefinition Height="Auto" MinHeight="10" />
                            <RowDefinition Height="Auto" MinHeight="20" />

                        </Grid.RowDefinitions>

                        <Label Content="From Date:" Grid.Row="0" Grid.Column="0"/>
                        <TextBox Text="01/01/2005" TextWrapping="Wrap" x:Name="fromDateTextBox"    Grid.Row="0" Grid.Column="1" >
                            <TextBox.InputScope>
                                <InputScope RegularExpression="\d\d/\d\d/\d\d\d\d"/>
                            </TextBox.InputScope>
                        </TextBox>

                        <Label Content="To Date:"  Grid.Column="0" Grid.Row="1"/>
                        <TextBox  TextWrapping="Wrap" VerticalAlignment="Bottom" Text="01/01/2006" x:Name="toDateTextBox"    Grid.Row="1" Grid.Column="1" >
                            <TextBox.InputScope>
                                <InputScope RegularExpression="\d\d/\d\d/\d\d\d\d" />
                            </TextBox.InputScope>
                        </TextBox>

                        <Label Content="Initial money:" Grid.Row="3" Grid.Column="0"/>
                        <TextBox   TextWrapping="Wrap" Text="{Binding Path=Default.InitialMoney, Source={StaticResource settings}}" x:Name="valueTextBox" Grid.Row="3" Grid.Column="1">
                            <TextBox.InputScope>
                                <InputScope RegularExpression="\d+" />
                            </TextBox.InputScope>
                        </TextBox>

                        <ComboBox   x:Name="currencySelector"   ItemsSource="{Binding Path=Currecnies, Source={StaticResource dataProvider}}" SelectedIndex="0" Grid.Row="3" Grid.Column="2">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <TextBlock Text="{Binding Path=.}" />
                                    </Grid>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>

                        <Label Content="Trade Commission (%):" Grid.Row="4" Grid.Column="0"/>
                        <TextBox   TextWrapping="Wrap" Text="{Binding Path=Default.Commission, Source={StaticResource settings}}" x:Name="commissionTextBox" Grid.Row="4" Grid.Column="1">
                            <TextBox.InputScope>
                                <InputScope RegularExpression="\d+" />
                            </TextBox.InputScope>
                        </TextBox>
                        
                        <Label Content="Yearly no risk interest%" Grid.Row="5" Grid.Column="0"/>
                        <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Path=Default.NoRiskInterest, Source={StaticResource settings}}" Name="interestTextBox" />
                        
                        <Label Content="Max risk (0&lt;risk&lt;1)" Grid.Row="6" Grid.Column="0"/>
                        <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=Default.MaxRisk, Source={StaticResource settings}}" Name="riskTextBox" />
                        
                        <Grid Grid.Row="7" Grid.ColumnSpan="3">
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Label Content="Signal generators:" Grid.Row="0" Grid.ColumnSpan="2"/>
                            <ListView SelectionMode="Multiple" MinHeight="60" Grid.Row="1" ItemsSource="{Binding Path=Signals, Source={StaticResource signalsFactory}, Mode=OneTime}" x:Name="signalsList" Grid.ColumnSpan="2"/>
                            <Button   Content="All"   Grid.Row="2"  Background="{DynamicResource ButtonsBrush}" Click="SelectAllSignals_Click" />
                            <Button   Content="Clear"   Grid.Row="2" Grid.Column="1" Background="{DynamicResource ButtonsBrush}" Click="Button_Click" />
                        </Grid>
                        
                        <Label Grid.Row="8"  />
                        
                        <Button  x:Name="tradeButton" Content="Trade!" Click="tradeButton_Click"     Grid.Row="9" Grid.ColumnSpan="2" Background="{DynamicResource ButtonsBrush}"     />
                        <ProgressBar x:Name="progressBar" Visibility="Hidden"   Grid.Row="10" Grid.ColumnSpan="3" Height="15"  />
                        <Label x:Name="stateLabel" Grid.Row="11" Grid.ColumnSpan="3" />

                        <Button x:Name="stopTraderButton" Click="stopTraderButton_Click" Visibility="Hidden"   Content="Stop Trading" Grid.Row="12" Grid.ColumnSpan="2" Background="{DynamicResource ButtonsBrush}"/>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="Results" Background="{x:Null}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Charts:XYLineChart x:Name="xyLineChartValue"  Grid.Row="0" Title="Portfolio state during trading"  XAxisLabel="Days in trading" YAxisLabel="Portfolio value"  />
                    <ListView x:Name="portfolioStatesListView"  Grid.Row="1" MouseDoubleClick="portfolioStatesListView_MouseDoubleClick" />
                    <Charts:XYLineChart x:Name="xyLineChartCommissions"  Grid.Row="2" Title="Commissions charged during trading" XAxisLabel="Days in trading" YAxisLabel="Commissions chraged"  />

                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Window>